package iterator.source;

/**
 * 具体迭代器类
 * @author cheng:
 * @date 2019/4/19 19:15
 */
public class ConcreteIterator implements Iterator{

    private ConcreteAggregate aggregate;
    private int current = 0;

    public ConcreteIterator(ConcreteAggregate aggregate) {
        this.aggregate = aggregate;
    }

    @Override
    public Object first() {
        return aggregate.get(0);
    }

    @Override
    public Object next() {
        Object o = null;
        current ++;
        if(current < aggregate.size()){
            o = aggregate.get(current);
        }
        return o;
    }

    @Override
    public boolean idDone() {
        return current >= aggregate.size() - 1;
    }

    @Override
    public Object currentItem() {
        return aggregate.get(current);
    }
}
